<%@ page import="gdepot.Orders" %>
<%@ page import="gdepot.Goods" %>

<script>
    function itemNumberChange(){
        var result=confirm("${message(code: 'cart.itemNumberUpdate.confirm')}")
        if(result){
            $("#changeItemNumberForm").submit()
            return true
        }
        $("#itemNumberUpdate").val($("#hiddenItemNumber").val())
        return false

    }
</script>


<div>

        <table class="table table-striped table-bordered">
            <thead>
            <th><g:message code="goods.title"/> </th>
            <th><g:message code="goods.price"/> </th>
            <th><g:message code="lineItem.itenNumber"/></th>
            <th></th>
            </thead>
            <tbody>
            <g:each in="${cart?.lineItems}" var="lineItem">
                <tr>
                    <td>${lineItem.goods?.title}</td>
                    <td>
                        ${lineItem.goods?.price}*${lineItem.itemNumber}
                    </td>

                    <td>

                        <form  controller="cart" action="changeItemNumber" id = "changeItemNumberForm" >
                            <g:hiddenField name="id" value="${lineItem.id}" />
                            %{--<input type="hidden" name="forwardURI" value="${request.forwardURI}?${request.queryString}" >--}%
                            <input type="text" id="hiddenItemNumber" value="${lineItem.itemNumber}" style="display: none" />
                            <input id="itemNumberUpdate" type="text" name="itemNumber" value="${lineItem.itemNumber}" size="2"
                                   onchange="itemNumberChange()"/>
                        </form>
                    </td>

                    <td>
                        <g:form controller="cart" action="removeFromCart" method="POST">
                            <input type="hidden" name="id" value="${lineItem.id}">
                            %{--<input type="hidden" name="forwardURI" value="${request.forwardURI}?${request.queryString}" >--}%
                            <input type="submit" class="btn btn-link"  value="${message( code:'cart.remove')}"
                                   onclick="return confirm('${message(code:'confirm.removeFromCart')}')">
                        </g:form>
                    </td>

                </tr>
            </g:each>
            </tbody>
            <tr>

                <td colspan="4">
                    <g:message code="cart.totalPrice"/>
                    ${cart.totalPrice()}
                </td>
            </tr>

        </table>


</div>
